package com.ciwong.epaper.modules.me.ui;

import android.content.Intent;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.android.volley.TimeoutError;
import com.aspsine.swipetoloadlayout.OnLoadMoreListener;
import com.aspsine.swipetoloadlayout.OnRefreshListener;
import com.aspsine.swipetoloadlayout.SwipeToLoadLayout;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.ciwong.epaper.R;
import com.ciwong.epaper.application.EApplication;
import com.ciwong.epaper.modules.clazz.bean.TeacherClassBean;
import com.ciwong.epaper.modules.epaper.adapter.BookDeskAdapter;
import com.ciwong.epaper.modules.epaper.adapter.BookDeskGridAdapter;
import com.ciwong.epaper.modules.epaper.bean.GradeBean;
import com.ciwong.epaper.modules.epaper.dao.EpaperDao;
import com.ciwong.epaper.modules.epaper.util.EpaperJumpManager;
import com.ciwong.epaper.modules.me.adapter.BookCategoryDeskGridAdapter;
import com.ciwong.epaper.modules.me.bean.BooksPage;
import com.ciwong.epaper.modules.me.bean.EpaperInfoGradeCategoryBean;
import com.ciwong.epaper.modules.me.bean.EpaperInfoGradeNameBean;
import com.ciwong.epaper.modules.me.bean.FavoritesBook;
import com.ciwong.epaper.modules.me.bean.ServiceProductsBean;
import com.ciwong.epaper.modules.me.widget.MarginDecoration;
import com.ciwong.epaper.util.BaseExtCallBack;
import com.ciwong.epaper.util.DisplayUtils;
import com.ciwong.epaper.util.IntentFlag;
import com.ciwong.epaper.util.IntentValue;
import com.ciwong.epaper.util.RequestCode;
import com.ciwong.libs.utils.CWLog;
import com.ciwong.libs.utils.NetworkUtils;
import com.ciwong.mobilelib.bean.SchoolDetail;
import com.ciwong.mobilelib.i.BaseQuickOnItemClickListener;
import com.ciwong.mobilelib.ui.BaseActivity;
import com.ciwong.mobilelib.utils.ToastUtil;
import com.ciwong.mobilelib.widget.NoScrollGridView;

import java.util.ArrayList;
import java.util.List;

/**
 * 标签书籍页面
 * 书籍UI和书桌旧版用的是同一个UI布局和ADAPTER  修改的时候需要注意一下
 */

public class BookTagActivity extends BaseActivity implements OnRefreshListener, OnLoadMoreListener {
    private RecyclerView mRvBookDesk;
    private BookDeskAdapter mBookDeskAdapter;
    private List<BooksPage> mEpaperInfoList = new ArrayList<>();
    private SwipeToLoadLayout mSwipeToLoadLayout;
    private int mBookmarkId;
    private int mPageIndex = 1;
    private int mPageSize = 15;
    private String mBookmarkTitle;
    private boolean mIsRefesh;
    private LinearLayout list_nodata;
    private ViewGroup listviewgroup;
    private Button btn_retry;
    private FavoritesBook favoritesBook;
    private TextView book_tag_title;
    private NoScrollGridView grand_name_grid;
    private BookDeskGridAdapter bookDeskGridAdapter;
    private List<EpaperInfoGradeNameBean> epaperInfoGradeNameBeans = new ArrayList<>();
    private List<BooksPage> epaperInfos = new ArrayList<>();

    private List<TeacherClassBean> teacherClassBeans = new ArrayList<>();
    private List<BooksPage> searchBookList = new ArrayList<BooksPage>();
    private String classIds;

    private ServiceProductsBean serviceProductsBean;
    //学校id
    private int schoolId;
    //学段id
    private int periodId;
    //年级id
    private int gradeId = -1;
    //书籍分类,1教材同步 2课外拓展 -1为所有
    private int bookType = 2;

    private int isOwn = 2;
    //关键字搜索
    private String keyWords;

    private int brandId;
    //服务ID
    private int serviceId;


    private NoScrollGridView grand_category_grid;
    private List<EpaperInfoGradeCategoryBean> mInfoGradeCategoryBean = new ArrayList<>();
    private BookCategoryDeskGridAdapter bookCategoryDridAdapter;
    private int mBookTypeId = 0;
    //服务器请求
    private int subCategoryId = 0;
    private boolean isShowSubCategory = false;


    @Override
    protected int setView() {
        return R.layout.fragment_book_desk;
    }

    @Override
    protected void findViews() {
        mRvBookDesk = findViewById(R.id.swipe_target);
        mSwipeToLoadLayout = findViewById(R.id.swipe_toLoad_layout);
        list_nodata = findViewById(R.id.ll_no_net);
        listviewgroup = findViewById(R.id.listviewgroup);
        btn_retry = findViewById(R.id.btn_retry);
        //book_tag_go_back = (ImageView) findViewById(R.id.book_tag_go_back);
        //    book_tag_title = (TextView) findViewById(R.id.book_tag_title);
        grand_name_grid = (NoScrollGridView) findViewById(R.id.grand_name_grid);
        grand_category_grid = findViewById(R.id.grand_category_grid);

    }

    @Override
    protected void initEvent() {

        mSwipeToLoadLayout.setOnRefreshListener(this);
        mSwipeToLoadLayout.setOnLoadMoreListener(this);
        btn_retry.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                loadData();
            }
        });
        /*book_tag_go_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });*/
    }

    @Override
    protected void init() {
        //hideTitleBar();
        mRvBookDesk.setLayoutManager(new GridLayoutManager(BookTagActivity.this, 3));
        mRvBookDesk.addItemDecoration(new MarginDecoration(BookTagActivity.this));
        mBookDeskAdapter = new BookDeskAdapter(R.layout.item_autonomic_book_case, mEpaperInfoList);
        mRvBookDesk.setAdapter(mBookDeskAdapter);
        bookDeskGridAdapter = new BookDeskGridAdapter(BookTagActivity.this, epaperInfoGradeNameBeans);
        grand_name_grid.setAdapter(bookDeskGridAdapter);


        CWLog.e("DisplayUtils ", DisplayUtils.getWidthInDp(BookTagActivity.this) + "");
        if (DisplayUtils.getWidthInDp(BookTagActivity.this) >= 900) {
            grand_name_grid.setNumColumns(6);
            grand_category_grid.setNumColumns(6);
        } else if (DisplayUtils.getWidthInDp(BookTagActivity.this) >= 700 && DisplayUtils.getWidthInDp(BookTagActivity.this) < 900) {
            grand_name_grid.setNumColumns(5);
            grand_category_grid.setNumColumns(5);
        } else if (DisplayUtils.getWidthInDp(BookTagActivity.this) >= 500 && DisplayUtils.getWidthInDp(BookTagActivity.this) < 700) {
            grand_name_grid.setNumColumns(4);
            grand_category_grid.setNumColumns(4);
        } else {
            grand_name_grid.setNumColumns(3);
            grand_category_grid.setNumColumns(4);
        }


        mBookDeskAdapter.setOnItemClickListener(new BaseQuickOnItemClickListener() {


            @Override
            public void avertRepeatOnClick(BaseQuickAdapter adapter, View view, int position) {
                try {
                    BooksPage epaperInfo = mEpaperInfoList.get(position);
                    if (null != epaperInfo) {
                        //if (epaperInfo.getIsExpire() == 1 || epaperInfo.getIsFree() == 1) {
                        favoritesBook = new FavoritesBook();
                        favoritesBook.setAppId(epaperInfo.getAppId());
                        favoritesBook.setBookIntro(epaperInfo.getBookIntro());
                        favoritesBook.setBookType(epaperInfo.getBookType());
                        favoritesBook.setCover(epaperInfo.getCover());
                        favoritesBook.setGrade(epaperInfo.getGrade());
                        favoritesBook.setSubject(epaperInfo.getSubject());
                        favoritesBook.setIsFree(epaperInfo.getIsFree());
                        favoritesBook.setPackageIsFree(epaperInfo.getPackageIsFree());
                        if (0 != epaperInfo.getProductId()) {
                            favoritesBook.setProductId(epaperInfo.getProductId());
                        }
                        if (null != epaperInfo.getPackageId() && !"".equals(epaperInfo.getPackageId())) {
                            favoritesBook.setPackageId(Integer.valueOf(epaperInfo.getPackageId()));
                        }
                        favoritesBook.setGradeName(epaperInfo.getGradeName());
                        favoritesBook.setRequired(epaperInfo.getRequired());
                        favoritesBook.setServiceId(Integer.valueOf(epaperInfo.getServiceId()));
                        favoritesBook.setServiceName(epaperInfo.getServiceName());
                        favoritesBook.setBookType(epaperInfo.getBookType());
                        favoritesBook.setTeamId(epaperInfo.getTeamId());
                        favoritesBook.setTeamName(epaperInfo.getTeamName());
                        favoritesBook.setBookIntro(epaperInfo.getBookIntro());
                        favoritesBook.setSort(epaperInfo.getSort());
                        favoritesBook.setIstop(epaperInfo.getIstop());
                        favoritesBook.setIsPwd(epaperInfo.getIsPwd());
                        favoritesBook.setPackageType(epaperInfo.getPackageType());
                        if (null != epaperInfo.getProductName()) {
                            favoritesBook.setProductName(epaperInfo.getProductName());
                        } else {
                            favoritesBook.setProductName("");
                        }
                        EpaperJumpManager.jumpToCatalog2(R.string.go_back, BookTagActivity.this, RequestCode.TeaWorkContent.HOME_WORK, favoritesBook, IntentValue.JumpToBookCatalogType.FROM_NEW_DESK_BOOK, RequestCode.MainActivityResquestCode.REQUEST_FAVORITEXS, Integer.valueOf(epaperInfo.getServiceId()));
                    }
                } catch (Exception e) {

                }
            }
        });
//        mBookDeskAdapter.setOnItemClickListener(new BaseQuickAdapter.BaseQuickOnItemClickListener() {
//            @Override
//            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
//                try {
//                    BooksPage epaperInfo = mEpaperInfoList.get(position);
//                    if (null != epaperInfo) {
//                        //if (epaperInfo.getIsExpire() == 1 || epaperInfo.getIsFree() == 1) {
//                        favoritesBook = new FavoritesBook();
//                        favoritesBook.setAppId(epaperInfo.getAppId());
//                        favoritesBook.setBookIntro(epaperInfo.getBookIntro());
//                        favoritesBook.setBookType(epaperInfo.getBookType());
//                        favoritesBook.setCover(epaperInfo.getCover());
//                        favoritesBook.setGrade(epaperInfo.getGrade());
//                        favoritesBook.setSubject(epaperInfo.getSubject());
//                        favoritesBook.setIsFree(epaperInfo.getIsFree());
//                        if (0 != epaperInfo.getProductId()) {
//                            favoritesBook.setProductId(epaperInfo.getProductId());
//                        }
//                        if (null != epaperInfo.getPackageId() && !"".equals(epaperInfo.getPackageId())) {
//                            favoritesBook.setPackageId(Integer.valueOf(epaperInfo.getPackageId()));
//                        }
//                        favoritesBook.setGradeName(epaperInfo.getGradeName());
//                        favoritesBook.setRequired(epaperInfo.getRequired());
//                        favoritesBook.setServiceId(Integer.valueOf(epaperInfo.getServiceId()));
//                        favoritesBook.setServiceName(epaperInfo.getServiceName());
//                        favoritesBook.setBookType(epaperInfo.getBookType());
//                        favoritesBook.setTeamId(epaperInfo.getTeamId());
//                        favoritesBook.setTeamName(epaperInfo.getTeamName());
//                        favoritesBook.setBookIntro(epaperInfo.getBookIntro());
//                        favoritesBook.setSort(epaperInfo.getSort());
//                        favoritesBook.setIstop(epaperInfo.getIstop());
//                        favoritesBook.setIsPwd(epaperInfo.getIsPwd());
//                        favoritesBook.setPackageType(epaperInfo.getPackageType());
//                        if (null != epaperInfo.getProductName()) {
//                            favoritesBook.setProductName(epaperInfo.getProductName());
//                        } else {
//                            favoritesBook.setProductName("");
//                        }
//                        EpaperJumpManager.jumpToCatalog2(R.string.go_back, BookTagActivity.this, RequestCode.TeaWorkContent.HOME_WORK, favoritesBook, IntentValue.JumpToBookCatalogType.FROM_NEW_DESK_BOOK, RequestCode.MainActivityResquestCode.REQUEST_FAVORITEXS, Integer.valueOf(epaperInfo.getServiceId()));
//                    }
//                } catch (Exception e) {
//
//                }
//
//            }
//        });
    }

    @Override
    protected void loadData() {
        mBookmarkId = getIntent().getIntExtra(IntentFlag.INTENT_FLAG_BOOKMARK, -1);
        mBookmarkTitle = getIntent().getStringExtra(IntentFlag.INTENT_FLAG_TITLE);
        //book_tag_title.setText(mBookmarkTitle);
        setTitleText(mBookmarkTitle);
        mIsRefesh = true;
        mPageIndex = 1;

        if (!NetworkUtils.isOnline()) {
            list_nodata.setVisibility(View.VISIBLE);
            listviewgroup.setVisibility(View.GONE);
        } else {
            list_nodata.setVisibility(View.GONE);
            listviewgroup.setVisibility(View.VISIBLE);
            showCricleProgress();
            getMyOneSchool();
            getGradeByBookmarkId();

            if (mBookmarkTitle.equals("听说")) {
                isShowSubCategory = true;
                mBookTypeId = 3;
            } else if (mBookmarkTitle.equals("跟读")) {
                mBookTypeId = 9;
                isShowSubCategory = true;
            } else {
                mBookTypeId = 0;
                isShowSubCategory = false;
            }
            if (isShowSubCategory) {
                findViewById(R.id.grand_category_grid).setVisibility(View.VISIBLE);
                initCategoryDate();
            } else {
                findViewById(R.id.grand_category_grid).setVisibility(View.GONE);
            }
        }
        initCategoryDate();
        setGrade();
    }

    private void initCategoryDate() {
        bookCategoryDridAdapter = new BookCategoryDeskGridAdapter(BookTagActivity.this, mInfoGradeCategoryBean);
        grand_category_grid.setAdapter(bookCategoryDridAdapter);
        getGradeByBookCategoryId();
    }

    public void getGradeByBookCategoryId() {
        EpaperDao.getInstance().getGradeByBookCategoryId(mBookTypeId, new BaseExtCallBack(BookTagActivity.this, EApplication.getInstance().getUserInfoBase().getUserId() + "") {
            @Override
            public void success(final Object data) {
                if (null != data) {
                    List<EpaperInfoGradeCategoryBean> gradeList = (List<EpaperInfoGradeCategoryBean>) data;
                    setNetCategoryGrade(gradeList);
                }
            }

            @Override
            public void failed(int errorCode, Object data) {
                //网络获取失败了再走本地获取流程
                super.failed(errorCode, data);
            }

            @Override
            public void failed(Object data) {
                super.failed(data);
            }
        });
    }

    /**
     * 填充网络数据
     *
     * @param gradeList
     */
    public void setNetCategoryGrade(List<EpaperInfoGradeCategoryBean> gradeList) {
        mInfoGradeCategoryBean = new ArrayList<>();
        EpaperInfoGradeCategoryBean epaperInfoGradeNameBean = new EpaperInfoGradeCategoryBean();
        epaperInfoGradeNameBean.setName("全部");
        epaperInfoGradeNameBean.setID(0);
        epaperInfoGradeNameBean.setChecked(true);
        mInfoGradeCategoryBean.add(epaperInfoGradeNameBean);
        for (int i = 0; i < gradeList.size(); i++) {
            EpaperInfoGradeCategoryBean item = gradeList.get(i);
            EpaperInfoGradeCategoryBean itemGrade = new EpaperInfoGradeCategoryBean();
            itemGrade.setName(item.getName());
            itemGrade.setID(item.getID());
            itemGrade.setChecked(false);
            mInfoGradeCategoryBean.add(itemGrade);
        }
        bookCategoryDridAdapter.setNewData(mInfoGradeCategoryBean);
    }


    public void getServiceProductsByIdCategoryids(int categoryId, final boolean isNeedRefresh) {
        this.subCategoryId = categoryId;
        if (isNeedRefresh) {
            onRefresh();
        }
    }

    /**
     * 获取学校信息
     */
    public void getMyOneSchool() {
        SchoolDetail mySchool = EApplication.getInstance().getMySchool();
        if (null == mySchool) {
            hideCricleProgress();
            return;
        }
        schoolId = mySchool.getSchoolId();
        periodId = mySchool.getPeriod();
        getMyClass(EApplication.BRAND_ID + "", 2, schoolId);
    }


    /**
     * 获取班级列表
     */
    public void getMyClass(String brandId, int userRole, int schoolId) {
        if (null != EApplication.getInstance().getUserInfoBase()) {
            EpaperDao.getInstance().getMyClass(brandId, userRole, schoolId, new BaseExtCallBack(BookTagActivity.this, EApplication.getInstance().getUserInfoBase().getUserId() + "") {
                @Override
                public void failed(int errorCode, Object data) {
                    super.failed(errorCode, data);
                    hideCricleProgress();
                    if (data instanceof TimeoutError) {
                        ToastUtil.INSTANCE.toastCenterError(getString(R.string.load_faild_check_net_work));
                    }
                }

                @Override
                public void failed(Object data) {

                    hideCricleProgress();
                    if (!NetworkUtils.isOnline()) {
                        ToastUtil.INSTANCE.toastCenterError(getString(R.string.load_faild_check_net_work));
                        return;
                    }
                    // ToastUtil.INSTANCE.toastCenterError("加载失败，检查网络重新请求");
                }

                @Override
                public void success(Object data) {
                    hideCricleProgress();
                    if (null != data && data instanceof ArrayList) {
                        teacherClassBeans = (List<TeacherClassBean>) data;
                        for (int i = 0; i < teacherClassBeans.size(); i++) {
                            if (i == 0) {
                                classIds = String.valueOf(teacherClassBeans.get(i).getClassId());
                            } else {
                                classIds = classIds + "," + teacherClassBeans.get(i).getClassId();
                            }
                        }
                        for (int i = 0; i < epaperInfoGradeNameBeans.size(); i++) {
                            if (null != epaperInfoGradeNameBeans.get(i).getChecked() && epaperInfoGradeNameBeans.get(i).getChecked()) {
                                getServiceProductsByIdClassids(epaperInfoGradeNameBeans.get(i).getGradeId(), false);
                            }
                        }
                    }
                }
            });
        } else {
            finish();
        }
    }

    /**
     * 获取书籍
     *
     * @param gradeId       年级id
     * @param isNeedRefresh 是否选择年级刷新数据
     */
    public void getServiceProductsByIdClassids(int gradeId, final boolean isNeedRefresh) {
        if (isNeedRefresh) {
            mPageIndex = 1;
        }
        EpaperDao.getInstance().getServiceProductsByIdClassids(EApplication.BRAND_ID, isOwn, mBookmarkId, serviceId,  subCategoryId+"", classIds, schoolId, gradeId, bookType, keyWords, mPageIndex, mPageSize, new BaseExtCallBack(BookTagActivity.this, EApplication.getInstance().getUserInfoBase().getUserId() + "") {

            @Override
            public void success(final Object data) {
                hideCricleProgress();
                mSwipeToLoadLayout.setRefreshing(false);
                mSwipeToLoadLayout.setLoadingMore(false);
                if (null != data) {
                    if (isNeedRefresh) {
                        if (null != mEpaperInfoList) {
                            mEpaperInfoList.clear();
                        }
                    }
                    serviceProductsBean = (ServiceProductsBean) data;
                    List<BooksPage> pageList = serviceProductsBean.getPageList();
                    if (mIsRefesh) {
                        if (pageList != null && pageList.size() >= 0) {
                            mEpaperInfoList = pageList;
                            mBookDeskAdapter.setNewData(mEpaperInfoList);
                        }
                    } else {
                        if (pageList != null && pageList.size() >= 0) {
//                            mEpaperInfoList.addAll(pageList);
                            mBookDeskAdapter.addData(pageList);
                        }
                    }
                    mIsRefesh = true;
                    //setGrade();

                }
            }

            @Override
            public void failed(int errorCode, Object data) {
                hideCricleProgress();
                mSwipeToLoadLayout.setRefreshing(false);
                mSwipeToLoadLayout.setLoadingMore(false);
                //网络获取失败了再走本地获取流程
                super.failed(errorCode, data);
                if (!NetworkUtils.isOnline()) {
                    ToastUtil.INSTANCE.toastCenterError(getString(R.string.load_faild_check_net_work));
                    return;
                }

            }

            @Override
            public void failed(Object data) {
                hideCricleProgress();
                mSwipeToLoadLayout.setRefreshing(false);
                mSwipeToLoadLayout.setLoadingMore(false);
                //               getLocData();
                super.failed(data);
                if (!NetworkUtils.isOnline()) {
                    ToastUtil.INSTANCE.toastCenterError(getString(R.string.load_faild_check_net_work));
                    return;
                }
            }

        });
    }

    /**
     * 获取书籍包含的年级列表
     */
    public void getGradeByBookmarkId() {
        EpaperDao.getInstance().getGradeByBookmarkId(EApplication.BRAND_ID, mBookmarkId, new BaseExtCallBack(BookTagActivity.this, EApplication.getInstance().getUserInfoBase().getUserId() + "") {
            @Override
            public void success(final Object data) {
                if (null != data) {
                    List<GradeBean> gradeList = (List<GradeBean>) data;
                    setNetGrade(gradeList);
                }
            }

            @Override
            public void failed(int errorCode, Object data) {
                //网络获取失败了再走本地获取流程
                super.failed(errorCode, data);
            }

            @Override
            public void failed(Object data) {
                super.failed(data);
            }
        });
    }

    /**
     * 填充网络数据
     *
     * @param gradeList
     */
    public void setNetGrade(List<GradeBean> gradeList) {
        epaperInfoGradeNameBeans = new ArrayList<>();
        EpaperInfoGradeNameBean epaperInfoGradeNameBean = new EpaperInfoGradeNameBean("全部", 0, true);
        epaperInfoGradeNameBean.setGradeName("全部");
        epaperInfoGradeNameBean.setGradeId(0);
        epaperInfoGradeNameBean.setChecked(true);
        epaperInfoGradeNameBeans.add(epaperInfoGradeNameBean);
        for (int i = 0; i < gradeList.size(); i++) {
            GradeBean item = gradeList.get(i);
            EpaperInfoGradeNameBean itemGrade = new EpaperInfoGradeNameBean(item.getGradeName(), item.getGrade());
            epaperInfoGradeNameBeans.add(itemGrade);
        }
        bookDeskGridAdapter.setNewData(epaperInfoGradeNameBeans);
    }

    /**
     * 初始化本地数据
     */
    public void setGrade() {
        epaperInfoGradeNameBeans = new ArrayList<>();
        EpaperInfoGradeNameBean epaperInfoGradeNameBean = new EpaperInfoGradeNameBean("全部", 0, true);
        epaperInfoGradeNameBean.setGradeName("全部");
        epaperInfoGradeNameBean.setGradeId(0);
        epaperInfoGradeNameBean.setChecked(true);
        epaperInfoGradeNameBeans.add(epaperInfoGradeNameBean);
        EpaperInfoGradeNameBean epaperInfoGradeNameBean1 = new EpaperInfoGradeNameBean("一年级", 1101);
        EpaperInfoGradeNameBean epaperInfoGradeNameBean2 = new EpaperInfoGradeNameBean("二年级", 1102);
        EpaperInfoGradeNameBean epaperInfoGradeNameBean3 = new EpaperInfoGradeNameBean("三年级", 1103);
        EpaperInfoGradeNameBean epaperInfoGradeNameBean4 = new EpaperInfoGradeNameBean("四年级", 1104);
        EpaperInfoGradeNameBean epaperInfoGradeNameBean5 = new EpaperInfoGradeNameBean("五年级", 1105);
        EpaperInfoGradeNameBean epaperInfoGradeNameBean6 = new EpaperInfoGradeNameBean("六年级", 1106);
        EpaperInfoGradeNameBean epaperInfoGradeNameBean7 = new EpaperInfoGradeNameBean("七年级", 1107);
        EpaperInfoGradeNameBean epaperInfoGradeNameBean8 = new EpaperInfoGradeNameBean("八年级", 1108);
        EpaperInfoGradeNameBean epaperInfoGradeNameBean9 = new EpaperInfoGradeNameBean("九年级", 1109);
        EpaperInfoGradeNameBean epaperInfoGradeNameBean11 = new EpaperInfoGradeNameBean("高一", 1111);
        EpaperInfoGradeNameBean epaperInfoGradeNameBean12 = new EpaperInfoGradeNameBean("高二", 1112);
        EpaperInfoGradeNameBean epaperInfoGradeNameBean13 = new EpaperInfoGradeNameBean("高三", 1113);
        EpaperInfoGradeNameBean epaperInfoGradeNameBean14 = new EpaperInfoGradeNameBean("其他", 333333);
        epaperInfoGradeNameBeans.add(epaperInfoGradeNameBean1);
        epaperInfoGradeNameBeans.add(epaperInfoGradeNameBean2);
        epaperInfoGradeNameBeans.add(epaperInfoGradeNameBean3);
        epaperInfoGradeNameBeans.add(epaperInfoGradeNameBean4);
        epaperInfoGradeNameBeans.add(epaperInfoGradeNameBean5);
        epaperInfoGradeNameBeans.add(epaperInfoGradeNameBean6);
        epaperInfoGradeNameBeans.add(epaperInfoGradeNameBean7);
        epaperInfoGradeNameBeans.add(epaperInfoGradeNameBean8);
        epaperInfoGradeNameBeans.add(epaperInfoGradeNameBean9);
        epaperInfoGradeNameBeans.add(epaperInfoGradeNameBean11);
        epaperInfoGradeNameBeans.add(epaperInfoGradeNameBean12);
        epaperInfoGradeNameBeans.add(epaperInfoGradeNameBean13);
        epaperInfoGradeNameBeans.add(epaperInfoGradeNameBean14);
        bookDeskGridAdapter.setNewData(epaperInfoGradeNameBeans);
    }

    @Override
    public void onRefresh() {
        mIsRefesh = true;
        mPageIndex = 1;
        for (int i = 0; i < epaperInfoGradeNameBeans.size(); i++) {
            if (null != epaperInfoGradeNameBeans.get(i).getChecked() && epaperInfoGradeNameBeans.get(i).getChecked()) {
                showCricleProgress();
                getServiceProductsByIdClassids(epaperInfoGradeNameBeans.get(i).getGradeId(), false);
            }
        }
        getGradeByBookmarkId();
    }

    @Override
    public void onLoadMore() {
        mIsRefesh = false;
        mPageIndex++;
        for (int i = 0; i < epaperInfoGradeNameBeans.size(); i++) {
            if (null != epaperInfoGradeNameBeans.get(i).getChecked() && epaperInfoGradeNameBeans.get(i).getChecked()) {
                showCricleProgress();
                getServiceProductsByIdClassids(epaperInfoGradeNameBeans.get(i).getGradeId(), false);
            }
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {
            switch (requestCode) {
                case RequestCode.MainActivityResquestCode.REQUEST_FAVORITEXS:
                    onRefresh();
                    break;
            }
        }
    }
}

